require(irr)
require(gplot)

roundScore<-function(escore){
  escore[escore<1.5] = 1
  escore[escore>=1.5 & escore<2.5]=2
  escore[escore >= 2.5 & escore < 3.5] = 3
  escore[escore >= 3.5 & escore < 4.5] = 4
  escore[escore>= 4.5 & escore < 5.5] = 5
  escore[escore>= 5.5] = 6
  return(escore)
}

PercentageExactMatch <-function(trueScore,fittedScore){
  nmatch = length(trueScore[trueScore == fittedScore])
  ntotal = length(trueScore)
  return(nmatch/ntotal*100)  
}

standDiff<-function(hscore,escore){
  mh1 = mean(hscore)
  me = mean(escore)
  res = (mh1 - me)/sqrt(var(hscore)+var(escore))
  return(res)
}


hscore = read.table('E:/rapidminerData/MachineLearning/EraterResults/arggen10_xv.sas7bdat.csv',sep=',',header=T)$ARG_SCORE1
ok = hscore != 0
hscore=hscore[ok]
#------------------linear model ------------------

b=read.table("C:/Users/jghao/Desktop/linearModel_arggen10_mbxv.csv",header=T,sep=',')[ok,]
escoreRND = roundScore(b$prediction.ARGSCORE.)
kappa2(cbind(hscore,escoreRND),weight="squared")
PercentageExactMatch(hscore,escoreRND)
cor(b$ARGSCORE,b$prediction.ARGSCORE.)
plot(b$ARGSCORE,b$prediction.ARGSCORE,xlab='HScore',ylab='EScore',pch=',',main='linear model')
table(hscore,escoreRND)
mean(hscore)
sd(hscore)
mean(escoreRND)
sd(escoreRND)
standDiff(hscore,escoreRND)



#-----------Gaussian Process Regression ------

b=read.table("C:/Users/jghao/Desktop/GP_arggen10_mbxv.csv",header=T,sep=',')[ok,]
escoreRND = roundScore(b$prediction.ARGSCORE.)
kappa2(cbind(hscore,escoreRND),weight="squared")
PercentageExactMatch(hscore,escoreRND)
cor(b$ARGSCORE,b$prediction.ARGSCORE.)
plot(b$ARGSCORE,b$prediction.ARGSCORE,xlab='HScore',ylab='EScore',pch=',',main='Gaussian Process')
table(hscore,escoreRND)
mean(hscore)
sd(hscore)
mean(escoreRND)
sd(escoreRND)
standDiff(hscore,escoreRND)

#-----------SVM -----

b=read.table("C:/Users/jghao/Desktop/SVM_arggen10_mbxv.csv",header=T,sep=',')[ok,]
escoreRND = roundScore(b$prediction.ARGSCORE.)
kappa2(cbind(hscore,escoreRND),weight="squared")
PercentageExactMatch(hscore,escoreRND)
cor(b$ARGSCORE,b$prediction.ARGSCORE.)
plot(b$ARGSCORE,b$prediction.ARGSCORE,xlab='HScore',ylab='EScore',pch=',',main='SVM(rbf kernel)')
table(hscore,escoreRND)
mean(hscore)
sd(hscore)
mean(escoreRND)
sd(escoreRND)
standDiff(hscore,escoreRND)

#-----ANN -------------------
b=read.table("C:/Users/jghao/Desktop/ANN_arggen10_mbxv.csv",header=T,sep=',')[ok,]
escoreRND = roundScore(b$prediction.ARGSCORE.+7)
kappa2(cbind(hscore,escoreRND),weight="squared")
PercentageExactMatch(hscore,escoreRND)
cor(b$ARGSCORE,b$prediction.ARGSCORE.)
plot(b$ARGSCORE,b$prediction.ARGSCORE.+7, xlab='HScore',ylab='EScore',pch=',',main='Neural Network')
table(hscore,escoreRND)
mean(hscore)
sd(hscore)
mean(escoreRND)
sd(escoreRND)
standDiff(hscore,escoreRND)

#-----KNN (20)-------------------
b=read.table("C:/Users/jghao/Desktop/20NN_arggen10_mbxv.csv",header=T,sep=',')[ok,]
escoreRND = roundScore(b$prediction.ARGSCORE.)
kappa2(cbind(hscore,escoreRND),weight="squared")
PercentageExactMatch(hscore,escoreRND)
cor(b$ARGSCORE,b$prediction.ARGSCORE.)
plot(b$ARGSCORE,b$prediction.ARGSCORE., xlab='HScore',ylab='EScore',pch=',',main='20 Nearest Neighbors')
table(hscore,escoreRND)
mean(hscore)
sd(hscore)
mean(escoreRND)
sd(escoreRND)
standDiff(hscore,escoreRND)

